class ZCL_API_MATER_SRV definition
  public
  create public .

public section.
  interfaces IF_HTTP_SERVICE_EXTENSION .
protected section.
private section.
ENDCLASS.



CLASS ZCL_API_MATER_SRV IMPLEMENTATION.


  method IF_HTTP_SERVICE_EXTENSION~HANDLE_REQUEST.
      TYPES:BEGIN of t_tab,
         itemcode TYPE string,
         itemname TYPE string,
         invntryuom TYPE string,
         zmode TYPE string,
      END OF t_tab.

      DATA:lt_tab TYPE TABLE OF t_tab,
           ls_tab TYPE t_tab.
      DATA:lt_tab1 TYPE TABLE OF ZPP_MATER,
           ls_tab1 TYPE ZPP_MATER.

      TYPES:BEGIN OF t_msg,
           state TYPE string,
           errormsg TYPE string,
           data TYPE string,
       END OF t_msg.
       DATA:lt_msg TYPE TABLE of t_msg.
       DATA:LV_LINE TYPE I.

    DATA(lv_method)  =  request->get_method( ).

    IF lv_method = CONV string( if_web_http_client=>post ).

      response->set_text('访问成功POST！' ).

      DATA(lv_text) = request->get_text( ).

      /ui2/cl_json=>deserialize(
      EXPORTING json = lv_text
      pretty_name = /ui2/cl_json=>pretty_mode-low_case
      CHANGING data = lt_tab ).

      IF lt_tab IS NOT INITIAL.

       clear:lt_tab1,lv_line.
        LOOP AT lt_tab INTO ls_tab.
          LS_TAB1-client = SY-mandt.
          MOVE-CORRESPONDING ls_tab to ls_tab1.
          APPEND ls_tab1 to lt_tab1.
          clear:ls_tab1,ls_tab.
        ENDLOOP.
"        MOVE-CORRESPONDING lt_tab TO lt_tab1.
"        MODIFY ZPP_MATER FROM TABLE @lt_tab1.
"        COMMIT WORK.

        DATA: lv_txt TYPE string,
              lv_str TYPE string.
        lv_line = lines( lt_tab1 ).
        lv_str = lv_line.
        IF SY-SUBRC = 0.
          CONCATENATE '数据更新成功，更新条目数:' lv_str INTO lv_txt.
          response->set_text( lv_txt ).
        ENDIF.

      ELSE.
        response->set_text('未获取到数据' ).
      ENDIF.

      " TODO EML
    ELSE.
      response->set_text('访问方式需要为POST！' ).
    ENDIF.

  endmethod.
ENDCLASS.
